#!/usr/bin/python
# encoding: utf-8
'''
@File    :   ghost_code.py
@Time    :   2020/03/11 21:54:19
@Author  :   fangkaijin 
@Version :   1.0
@Contact :   fangkaijin@gmail.com
@License :   杭州移动互联
@Desc    :   None
'''

# 导入库包

import sys, os
import math

def is_odd(n):
    return n % 2 == 0
l = list(filter(is_odd, range(1,10)))
print(l)

def str_no_empy(n):
    return n and n.strip()

l = ['', '小黑', '小花', '']

print(tuple(filter(str_no_empy, l)))

def _odd_iter():
    n = 1
    while True:
        n = n+2
        yield n

def _not_divisible(n):
    return lambda x: x % n ==0

def primes():
    yield 2
    it =  _odd_iter()
    while True:
        n = next(it)
        yield n
        it = filter(_not_divisible(n), it)

#打印
for n in primes():
    if n < 30:
        print(n)
    else:
        break

#lanbda 测试
def test_lambda():
    return lambda x : x % 2 == 0

print(list(filter(test_lambda(), range(1,10))))

#返回函数
def calc_num(*args):
    ax = 0
    for n in args:
        ax += n
    return ax

#list 类型前面加*转换为可变参数
print(calc_num(*range(1, 10)))

#返回函数
def layz_calc_num(*args):
    def sum():
        ax = 0
        for n in args:
            ax += n
        return ax
    return sum
f = layz_calc_num(*range(1, 90))
print(f)
print(f())

#闭包
def cout(*args):
    def f(j):
        def g():
            return math.pow(j, 2)
        return g
    fs = []
    for i in args:
        fs.append(f(i))
    return fs

l = cout(*range(1, 10))
for index in l:
    print(index())

print(list(range(1,2)))
